//
//  BestMusicHeadTableViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/11/3.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "BestMusicHeadTableViewCell.h"

@interface BestMusicHeadTableViewCell()
@property (nonatomic,strong)UIImageView *titleImageView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *contentTitleLabel;
@property (nonatomic,strong)UILabel *contentLabel;
@property (nonatomic,strong)UILabel *ownerLabel;
@property (nonatomic,strong)UIImageView *ownerImageView;
@property (nonatomic,strong)UILabel *ownerNickLabel;
@end

@implementation BestMusicHeadTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_titleImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        
        self.contentTitleLabel = [[UILabel alloc] init];
        self.contentTitleLabel.textAlignment = NSTextAlignmentCenter;
        self.contentTitleLabel.textColor = [UIColor grayColor];
        self.contentTitleLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_contentTitleLabel];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.numberOfLines = 0;
        [self.contentLabel sizeToFit];
        self.contentLabel.font = [UIFont systemFontOfSize:13];
        self.contentLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_contentLabel];
        
        self.ownerLabel = [[UILabel alloc] init];
        self.ownerLabel.textAlignment = NSTextAlignmentRight;
        self.ownerLabel.textColor = [UIColor grayColor];
        self.ownerLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_ownerLabel];
        
        self.ownerImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_ownerImageView];
        
        self.ownerNickLabel = [[UILabel alloc] init];
        self.ownerNickLabel.textAlignment = NSTextAlignmentLeft;
        self.ownerNickLabel.textColor = [UIColor grayColor];
        self.ownerNickLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_ownerNickLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleImageView.frame = CGRectMake(FM_Screen_Pts_Width*10, FM_Screen_Pts_Height*20, FM_Screen_Pts_Width*30, FM_Screen_Pts_Width*30);
    self.titleLabel.frame = CGRectMake(FM_Screen_Pts_Width*45, FM_Screen_Pts_Height*20, FM_Screen_Width-FM_Screen_Pts_Width*55, FM_Screen_Pts_Height*30);
    self.contentTitleLabel.frame = CGRectMake(0, FM_Screen_Pts_Height*20+FM_Screen_Pts_Width*50, FM_Screen_Width, FM_Screen_Pts_Height*30);
}

- (void)setHeight:(CGFloat)height
{
    if(_height != height){
        _height = height;
    }
}

- (void)setHeadDic:(NSDictionary *)headDic
{
    if (_headDic != headDic) {
        _headDic = headDic;
    }
    [self setHeadInfo:headDic];
}

- (void)setHeadInfo:(NSDictionary *)headDic
{
    self.titleImageView.image = [UIImage imageNamed:@"findsubject_cover@2x.png"];
    self.titleLabel.text = [self.headDic objectForKey:@"title"];
    self.contentTitleLabel.text = @"简 介";
   
    NSString *contentStr = [self.headDic objectForKey:@"intro"];
    self.contentLabel.frame = CGRectMake(FM_Screen_Pts_Width*10, FM_Screen_Pts_Height*20+FM_Screen_Pts_Width*80, FM_Screen_Width-FM_Screen_Pts_Width*20, self.height);
    self.contentLabel.text = contentStr;
    
    // 作者昵称
    NSString *nickStr = [self.headDic objectForKey:@"nickname"];
    CGRect nickRect = [nickStr boundingRectWithSize:CGSizeMake(FM_Screen_Width, FM_Screen_Pts_Height*30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    self.ownerNickLabel.frame = CGRectMake(FM_Screen_Width-FM_Screen_Pts_Width*20-nickRect.size.width, self.height+FM_Screen_Pts_Height*20+FM_Screen_Pts_Width*80, nickRect.size.width, FM_Screen_Pts_Height*30);
    self.ownerNickLabel.text = nickStr;

    // 头像
    self.ownerImageView.frame = CGRectMake(self.ownerNickLabel.frame.origin.x-FM_Screen_Pts_Width*18, self.ownerNickLabel.frame.origin.y+(FM_Screen_Pts_Height*30-FM_Screen_Pts_Width*13)/2, FM_Screen_Pts_Width*13, FM_Screen_Pts_Width*13);
    self.ownerImageView.layer.cornerRadius = self.ownerImageView.frame.size.height/2;
    self.ownerImageView.layer.masksToBounds =YES;
    [self.ownerImageView sd_setImageWithURL:[NSURL URLWithString:[self.headDic objectForKey:@"smallLogo"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    // 小编
    self.ownerLabel.frame = CGRectMake(self.ownerImageView.frame.origin.x-FM_Screen_Pts_Width*55, self.height+FM_Screen_Pts_Height*20+FM_Screen_Pts_Width*80, FM_Screen_Pts_Width*50, FM_Screen_Pts_Height*30);
    self.ownerLabel.text = @"小编";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.contentView.backgroundColor = [UIColor whiteColor];
}

@end
